<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
		<title>获取帖子ID - HLX Tool</title>
		<link rel="icon" href="favicon.ico" type="image/ico">
		<meta name="author" content="XRLH">
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<link href="css/materialdesignicons.min.css" rel="stylesheet">
		<link href="css/style.min.css" rel="stylesheet">
		<!--对话框-->
		<link rel="stylesheet" href="js/jconfirm/jquery-confirm.min.css">
	</head>

	<body>
		<div class="container-fluid p-t-15">

			<div class="row">
				<div class="col-lg-12">
					<div class="card">
						<div class="card-header">
							<h4>获取帖子ID</h4>
						</div>
						<div class="card-body">
							<div class="input-group">
								<input type="text" class="form-control" placeholder="请输入帖子链接...(前后不要空格)" id="url">
								<span class="input-group-btn">
									<button class="btn btn-default" id="check" type="button">查询</button>
								</span>
							</div>
						</div>
					</div>
				</div>
			</div>

		</div>

		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/bootstrap.min.js"></script>
		<!--对话框-->
		<script src="js/jconfirm/jquery-confirm.min.js"></script>
		<!--消息提示-->
		<script src="js/bootstrap-notify.min.js"></script>
		<script type="text/javascript" src="js/lightyear.js"></script>
		<script type="text/javascript" src="js/main.min.js"></script>
		<script type="text/javascript">
			$("#check").click(function() {
				lightyear.loading('show');
				$.get("./api/postid.php", {
					"action": "getpostid",
					"url": $("#url").val()
				}, function(res) {
					lightyear.loading('hide');
					if (res.code == 200) {
						$.confirm({
							title: '成功',
							content: '查询成功！帖子ID为<span style="color:red;">' + res.msg + '</span>',
							type: 'green',
							buttons: {
								omg: {
									text: '复制',
									btnClass: 'btn-green',
									action: function() {
										var flag = copyText(res.msg); //这个必须在DOM对象的事件线程中执行
										if (flag) {
											lightyear.notify('复制成功！', 'success', 100,
												'mdi mdi-emoticon-happy', 'top', 'center');
										}
									}
								},
								close: {
									text: '关闭',
								}
							}
						});
					} else {
						lightyear.notify(res.msg, 'danger', 1000, 'mdi mdi-emoticon-happy', 'top', 'center');
					}
				}, "json");
			});

			function copyText(text) {
				var textarea = document.createElement("textarea");
				var currentFocus = document.activeElement;
				document.body.appendChild(textarea);
				textarea.value = text;
				textarea.focus();
				if (textarea.setSelectionRange) {
					textarea.setSelectionRange(0, textarea.value.length);
				} else {
					textarea.select();
				}
				try {
					var flag = document.execCommand("copy");
				} catch (eo) {
					var flag = false;
				}
				document.body.removeChild(textarea);
				currentFocus.focus();
				return flag;
			}
		</script>
	</body>
</html>
